package cn.lanqiao.ui;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import java.awt.Font;
import javax.swing.JButton;
import cn.lanqiao.entity.Student;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JTextPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.LineBorder;

public class StudentMainFrm extends JFrame {

	private static final long serialVersionUID = -8774379890453926801L;
	private JTable table;
	private JTable StudentScore;
	private JTextField txtPassword;
	private JTextField txtPasswordagain;
	private static String account;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StudentMainFrm frame = new StudentMainFrm(account);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public StudentMainFrm(String account) {
		
		setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
		getContentPane().setLayout(null);

		JTabbedPane StudentInfFrm = new JTabbedPane(JTabbedPane.TOP);
		StudentInfFrm.setBounds(0, 0, 550, 515);
		getContentPane().add(StudentInfFrm);

		JPanel Information = new JPanel();
		Information.setBackground(Color.WHITE);
		StudentInfFrm.addTab("学籍信息", null, Information, null);
		StudentInfFrm.setBackgroundAt(0, Color.WHITE);
		StudentInfFrm.setFont(new Font("微软雅黑", Font.PLAIN, 20));

		Information.setLayout(null);

		cn.lanqiao.service.UserService studentInformation = new cn.lanqiao.service.impl.UserServiceImpl();
		Student student = studentInformation.getStudentinformation(account);

		JLabel label_3 = new JLabel("姓名：");
		label_3.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label_3.setBounds(43, 85, 72, 26);
		Information.add(label_3);

		JLabel label_4 = new JLabel("学号：");
		label_4.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label_4.setBounds(43, 34, 72, 28);
		Information.add(label_4);

		JLabel label_5 = new JLabel("性别：");
		label_5.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label_5.setBounds(43, 139, 72, 28);
		Information.add(label_5);

		JLabel label_6 = new JLabel("学院：");
		label_6.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label_6.setBounds(43, 192, 72, 26);
		Information.add(label_6);

		JLabel label_7 = new JLabel("专业：");
		label_7.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label_7.setBounds(43, 231, 88, 40);
		Information.add(label_7);

		JLabel label_8 = new JLabel("班级：");
		label_8.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label_8.setBounds(43, 284, 88, 44);
		Information.add(label_8);

		JLabel label_9 = new JLabel("入学时间：");
		label_9.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label_9.setBounds(43, 341, 113, 37);
		Information.add(label_9);

		JTextPane txtSid = new JTextPane();
		txtSid.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		txtSid.setText(account);
		txtSid.setBounds(171, 34, 109, 38);
		Information.add(txtSid);

		JTextPane txtSname = new JTextPane();
		txtSname.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		txtSname.setText(student.getSname());
		txtSname.setBounds(171, 76, 88, 41);
		Information.add(txtSname);

		JTextPane txtGender = new JTextPane();
		txtGender.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		txtGender.setText(student.getSgender());
		txtGender.setBounds(171, 140, 88, 37);
		Information.add(txtGender);

		JTextPane txtScollege = new JTextPane();
		txtScollege.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		txtScollege.setText(student.getScollege());
		txtScollege.setBounds(171, 191, 251, 42);
		Information.add(txtScollege);

		JTextPane txtSmajor = new JTextPane();
		txtSmajor.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		txtSmajor.setText(student.getSmajor());
		txtSmajor.setBounds(170, 231, 135, 40);
		Information.add(txtSmajor);

		JTextPane txtSclass = new JTextPane();
		txtSclass.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		txtSclass.setText(student.getSclass());
		txtSclass.setBounds(171, 291, 75, 37);
		Information.add(txtSclass);

		JTextPane txtSenrol = new JTextPane();
		txtSenrol.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		txtSenrol.setText(student.getSenrol());
		txtSenrol.setBounds(170, 341, 135, 37);
		Information.add(txtSenrol);

		JScrollPane StudentCourse = new JScrollPane();
		StudentCourse.setViewportBorder(new LineBorder(new Color(0, 0, 0)));
		StudentInfFrm.addTab("个人选课", null, StudentCourse, null);
		StudentInfFrm.setBackgroundAt(1, Color.WHITE);

		cn.lanqiao.dao.StudentDao studentCourse = new cn.lanqiao.dao.impl.StudentDaoImpl();

		table = new JTable();
		table.setFillsViewportHeight(true);
		table.setModel(new DefaultTableModel(studentCourse.getCourse(account), new String[] { "您选了以下课程：" }));
		table.setRowHeight(30);
		table.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		StudentCourse.setViewportView(table);

		JScrollPane scrollPane = new JScrollPane();
		StudentInfFrm.addTab("个人成绩", null, scrollPane, null);
		StudentInfFrm.setBackgroundAt(2, Color.WHITE);

		StudentScore = new JTable();
		StudentScore.setFillsViewportHeight(true);
		StudentScore.setBorder(new LineBorder(new Color(0, 0, 0)));
		cn.lanqiao.dao.StudentDao grade = new cn.lanqiao.dao.impl.StudentDaoImpl();
		StudentScore.setRowHeight(30);
		StudentScore.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		StudentScore.setModel(new DefaultTableModel(grade.getSidSgrade(account), new String[] { "科目", "成绩" }));
		scrollPane.setViewportView(StudentScore);

		JPanel StudentChangePassword = new JPanel();
		StudentChangePassword.setBackground(Color.WHITE);
		StudentInfFrm.addTab("修改密码", null, StudentChangePassword, null);
		StudentInfFrm.setBackgroundAt(3, Color.WHITE);
		StudentChangePassword.setLayout(null);

		JButton save = new JButton("保存修改");
		save.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 修改密码取确认
				cn.lanqiao.dao.StudentDao passwords = new cn.lanqiao.dao.impl.StudentDaoImpl();
				String password = txtPassword.getText();
				String passwordagin = txtPasswordagain.getText();

				if (password.isEmpty() || passwordagin.isEmpty()) {
					JOptionPane.showMessageDialog(null, "请在输入框输入需要修改的密码!");
				} else {
					if (password.equals(passwordagin)) {
						passwords.changeupassword(account, passwordagin);
						JOptionPane.showMessageDialog(null, "修改成功!");
						txtPassword.setText(null);
						txtPasswordagain.setText(null);
					} else {
						JOptionPane.showMessageDialog(null, "两次密码输入不一致!请重新输入!");
					}
				}
			}
		});
		save.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		save.setBounds(342, 379, 128, 41);
		StudentChangePassword.add(save);

		JLabel label = new JLabel("新密码：");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label.setBounds(116, 72, 122, 41);
		StudentChangePassword.add(label);

		txtPassword = new JTextField();
		txtPassword.setBounds(268, 74, 170, 43);
		StudentChangePassword.add(txtPassword);
		txtPassword.setColumns(10);

		JLabel label_1 = new JLabel("再次确认密码：");
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label_1.setBounds(116, 173, 140, 33);
		StudentChangePassword.add(label_1);

		txtPasswordagain = new JTextField();
		txtPasswordagain.setBounds(268, 172, 170, 41);
		StudentChangePassword.add(txtPasswordagain);
		txtPasswordagain.setColumns(10);
		setBounds(100, 100, 566, 559);
		StudentMainFrm.this.setLocationRelativeTo(null);
	}
}
